package wrapper;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Vector;

/**
 * @Author Mr.Wen
 * @Version 1.0
 */
@SuppressWarnings("all")
public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入:");
        String next = scanner.next();

    }

    @Test
    void test() {
        Integer integer = 23;
        System.out.println("integer = " + integer);
        int a = 23;
        ArrayList<Object> list = new ArrayList<>();
        list.add(a);
        System.out.println(list);
        System.out.println(integer == a);

        Integer ii2 = a + 5;/*自动装箱*/
        System.out.println("ii2 = " + ii2);
        int i2 = ii2;/*自动拆箱*/
        System.out.println("i2 = " + i2);

    }

    @Test
    void test2() {
        String s1 = "123";
        int i = Integer.parseInt(s1);
        System.out.println(i + 20);
        String s2 = "123a";
//        int i2 = Integer.parseInt(s2);
    }

    @Test
    void test3() {
        Vector<Integer> v = new Vector<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩: ");
        int nextInt = scanner.nextInt();
        v.add(nextInt);
        System.out.println(v);
    }


    @Test/*!!!*/
    void test4() {
//        TODO Integer包装类面试问题
        Integer x = 127;
        Integer y = 127;
        System.out.println(x == y);/*true*/  /*从IntegerCache数组中取来的,内存地址一致*/
        /*享元设计模式*/
        /*除了Float,Double,Character,Boolean都有这种享元模式*/
        Integer x1 = 128;
        Integer y1 = 128;
        System.out.println(x1 == y1);/*false*/ /*两次都是new的新Integer对象,内存地址不一致*/
    }

    @Test
    void test5() {
        Integer i1 = 10;
        int i2 = 10;
        System.out.println(i1 == i2);/*自动拆箱成int,在栈常量池中是同一个int*/

        double d1 = 3;
        Integer d2 = 3;
        System.out.println(d1 == d2);/*true  Integer拆箱成int然后i2d转为double基本类型*/
    }

}
